<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width"/>
		<meta name="format-detection" content="telephone=no"/>
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/common.css" />
		<style type="text/css">
		</style>
	</head>
	<body></body>
	<script type="text/javascript" src="../../script/jquery-1.11.3.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/doT.min.js"></script>
	<script type="text/javascript" src="../../script/navigate.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/GPS.js"></script>
	<script type="text/javascript" src="../../script/debug.js"></script>
	<script type="text/javascript" src="../../script/config.js"></script>
	<script type="text/javascript" src="../../script/client.api.js"></script>

	<script>
		var wgs;
	 	var bdlat;
	 	var bdlon;
		var stationlistMap;
		var userlistMap;
		apiready = function() {
			var aMap = api.require('bMap');
			var lastLocation = $api.getStorage('LAST_GPS_LOCATION');

			api.showProgress({
				title : '加载中……',
				modal : true
			});
			$client.FdManagerMap({},function(ret,err){
				console.log(JSON.stringify(ret.resultList));
				if(ret.success){
				  stationlistMap=ret.resultList;
					var stationlocationlist=[];
					for (var i = 0; i < stationlistMap.length; i++) {
						stationlocationlist.push({
							id : i,
							lon : Number(stationlistMap[i].lon),
							lat : Number(stationlistMap[i].lat)
						});
					}



					aMap.open({
						rect : {
							x : 0,
							y : 0,
							w : api.frameWidth,
							h : api.frameHeight
						},
						center : {
							lon : lastLocation.lon,
							lat : lastLocation.lat
						},
						fixedOn : api.frameName,
						showUserLocation:true,
						zoomLevel : 10
					}, function(ret, err) {
						if (ret && ret.status) {
							aMap.getLocation(function(ret, err) {
							    if (ret.status) {
										aMap.setCenter({
											coords: {
													lon: ret.lon,
													lat: ret.lat
											},
											animation: false
										});
							    }
							});
						}
					});


					//设置标注点 站址
					aMap.addAnnotations({
						annotations : stationlocationlist,
						draggable: false,
						icon: 'widget://icon/location.png'
					}, function(ret, err) {
						api.closeFrame({
								name: 'mapDownDetail'
						});
							api.openFrame({
											name: 'mapDownDetail',
											url: 'mapDownDetail.html',
											pageParam:{
												stationlistMap:stationlistMap[ret.id]
											},
											rect: {
															x:0,
															y:api.winHeight-170,
															w:api.winWidth,
															h:170
											},
											bounces:false
							});
					});

					// //设置点击弹出框 站址
					// for (var i = 0; i < stationlistMap.length; i++) {
					// 	var stationMap = stationlistMap[i];
					// 	aMap.setBubble({
					// 		id: i,
					// 		content: {
					// 				title: stationMap.station_name,
					// 				subTitle: '经度:'+stationMap.lon+'纬度:'+stationMap.lat,
					// 		},
					// 		styles: {
					// 				titleColor: '#000',
					// 				titleSize: 14,
					// 				subTitleColor: '#999',
					// 				subTitleSize: 12,
					// 				illusAlign: 'left',
					// 				w:800,
					// 				h:200
					// 		}
					// 	}, function(ret) {
					// 		if (ret.eventType == 'clickContent') {
					// 						openStationDetail(ret.id);
					// 				}
					// 	});
					// }

					//设置比例尺
					aMap.setScaleBar({
						show : true
					});

					api.hideProgress();
				}else {
					api.toast({
							msg: ret.data_info,
							duration: 2000,
							location: 'bottom'
					});
				}
			})

		};

		/**
		 *打开该站址下工单
		 */
		function openStationDetail(id) {
				var params = {
						code : stationlistMap[id].code
				}

				api.openWin({
						name : 'fdstation',
						url : 'powerstation-list-fd.html',
						opaque : true,
						bounces : false,
						reload : true,
						pageParam : params,
						vScrollBarEnabled : false
				});
		}


	</script>
</html>
